home *** CD-ROM | disk | FTP | other *** search
- Path: baygate.bayarea.net!usenet
- From: Amir@bayarea.net (Amir)
- Newsgroups: comp.lang.c++,comp.lang.c
- Subject: Re: HELP on abstraction!!!
- Date: Sun, 07 Apr 1996 00:04:08 GMT
- Organization: Bay Area Internet Solutions (408)447-8690
- Message-ID: <316704f9.4805163@news>
- References: <4jok9c$a6e@merkurius.lu.se>
- NNTP-Posting-Host: amir.bayarea.net
- X-Newsreader: Forte Agent .99d/32.168
-
- On 1 Apr 1996 13:04:44 GMT, magnus_dahlberg@hermes.ics.lu.se (Magnus
- Dahlberg) wrote:
-
- >Hello everyone!
- >
- >I'm writing a C++ programme that should be able to use both arrays and
- >linked lists without changing the functions. Is it possible, for
- >example, to insert a new person in my list (queue) without knowing if
- >it's an array or a linked list? And if it is, how do I do it?
- >
- >Please, I need help quickly!
- >Send your answers to: magnus_dahlberg@hermes.ics.lu.se
- >
- >Thanx!
- >
- >
-
- Sure, all you need to have a common base class to the array and the
- link list, and than just have the method as a virtual like:
-
- class Common {
- ...
- public:
- virtual Error AddMember(Person & P) = 0;
- ...
- };
-
- class MyArray : public Common {
- ...
- public:
- virtual Error AddMember(Person & P);
- ...
- };
-
-
- class MyList public Common {
- ...
- public:
- virtual Error AddMember(Person & P);
- ...
- };
-
- ...
-
-
- Amir
-
- \\||||//
- \ o o /
- ______________.ooO__( () )__Ooo._______________________________
-
- Amir Deutel http://www.bayarea.net/~amir/
-
- .oo0O O0oo. Work: Amir.D@AppleLink.Apple.com
- ( ) ( ) Home: Amir@bayarea.net
- __________________\ (_____) /____________________________________
- \_) (_/
-